<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>fetch发送ajax请求</title>
  </head>
  <body>
    <button>点击发送</button>
    <script>
      const btn = document.querySelector("button");

      btn.onclick = function () {
        fetch("http://127.0.0.1:8080/fetch-server?vip=true", {
          // 请求方式
          method: "POST",
          // 请求头
          headers: {
            name: "mannoname",
            id: 40,
          },
          // 请求体
          body: "username=admin&password=admin",
        })
          .then((response) => {
            return response.text();
            // return response.json();
          })
          .then((response) => {
            console.log(response);
          });
      };
    </script>
  </body>
</html>
